﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Test_Connection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            SqlConnection conn = new SqlConnection("Data Source=172.25.17.124; Network Library=DBMSSOCN; Initial Catalog=cdtTestDb;User ID=NOE\\aljarrah; Password=jarrah1988;");
            //SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\aljarrah\\Desktop\\cdtTestDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
            SqlDataReader rdr = null;


            try
            {
                try
                {
                    conn.Open();
                }
                catch
                {
                    MessageBox.Show("Opened");
                }

                SqlCommand cmd = new SqlCommand("select * from dbo.Content", conn);

                try
                {
                    rdr = cmd.ExecuteReader();
                }
                catch
                {
                    MessageBox.Show("Reader Executed");
                }

                SqlDataAdapter ADP = new SqlDataAdapter(cmd);
                DataTable DT = new DataTable();
                try
                {
                    ADP.Fill(DT);
                }
                catch
                {

                    MessageBox.Show("Data table filled");
                }

                try
                {
                    dataGridView1.DataSource = DT;
                }

                catch
                {
                    MessageBox.Show("data grid");
                }
                while (rdr.Read())
                {
                    MessageBox.Show("hi");

                }


            }
            catch
            {
                MessageBox.Show("error");
            }
            finally
            {
                // close the reader
                if (rdr != null)
                {
                    rdr.Close();
                }

                // 5. Close the connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
    }
}
